​ENGE 1215 D3. MATLAB Challenge #3 Fall 2024Matlab

MATLAB挑战:库存与碳排放数据分析

Java Python ENGE 1215

Fall 2024

D3. MATLAB Challenge #3

(Individual – 5 points)

Due by Thursday, October 10, 2024

Purpose

In this MATLAB challenge, you will be introduced to output methods for informing users/consumers like plots and data analysis. This assignment also encompasses learning MATLAB’s basic input and output of data files. This challenge will help you learn how to create outputs with various formats in the command window, to save data, and to import data and use it. You will also need to analyze the data you see to give an informed opinion on the situation. This challenge is divided into two problems. For each problem, write formatted text, % comments, and code within the provided .mlx template.   Work for each problem should be part of a section that you could run individually, or altogether with the rest of the code as described in class.

Reminders

A few reminders as you prepare your solution:

1) Start with the provided mlx template and replace the name and date place holders at the top of the mlx file with your own information.

2) You will need to add comments (these can be text mode in the mlx and/or % comments within the code) to explain major sections of the code.

3) It is also good practice to use clear and clc as the first executable commands.  Use the semicolon (;) to suppress echoes of value assignment statements.

4) Input prompts should be designed so that the user understands what they need to enter.

5) Output should include text to describe what values are being output as well as the values themselves.

6) Unless otherwise stated, you may use any output method you prefer (disp or fprintf).   Your output text and values may show on a single line or multiple lines.

7) Any images should have legible text.

8) Remember that MATLAB does not allow any special characters in the file name except the underscore.

9) Use the variable naming conventions described in lecture.

10) Remember to use the appropriate file naming conventions.

Problem 1 (of 2): Dry Erase Markers

As the new boss of an office supplies company in Pennsylvania, one of your jobs is to keep track of the number of dry erase markers in your inventory. Typically, your company manages to sell 250 dry erase markers in one week. Initially, you have 5000 dry erase markers in your warehouse. Based on manufacturing and shipping constraints, your current dry erase marker supplier periodically ships a certain number of dry erase markers every 4 weeks. Use MATLAB to figure out how many dry erase markers you will be left with by the end of the year (52 weeks).

Your program should:

1. Create a variable called ‘initialInventory’ that stores the number of dry erase markers initially in the warehouse.

2. Create a variable called ‘sellRate’ that stores the number of dry erase markers sold each week.

3. Create a time vector containing the week number (1 to 52).  This vector should be stored in a variable called ‘weekNumber’.

4. Read the StationerySupplier1.csv file (you can download a copy from the D3 link) that contains a running sum (cumulative sum) of the dry erase markers that the supplier has sent you so far. Store the cumulative dry erase markers you receive as a vector in a variable called ‘cumulSupply’.

5. Calculate the number of dry erase markers in the inventory every week using the following formula: inventory = initialInventory - sellRate*weekNumber + cumulSupply

6. Combine the vectors into a single two-column matrix. Column 1 should contain the week number and column two should contain the number of dry erase markers in the inventory (the vector inventory).

7. Create a .csv file containing the two-column matrix and name it as follows “LastnameFirstname_Inventory.csv”

8. Display a message that contains the number of dry erase markers left in your inventory at the end of the year.

Create a sample run.  The first five rows of your csv file from your resulting run may look similar to this:

Week number

Number of dry erase markers in inventory

1

5731

2

5481

3

5231

4

4981

5

5455

Problem 2 (of 2): Carbon Footprint

You are tasked with analyzing the carbon footprint of a fleet of vehicles. The fleet manager has provided you with data on the number of miles driven by various vehicles of a certain size in the fleet and the corresponding amount of carbon dioxide (CO2) emissions recorded. Your task is to use this data to better understand the relationship between miles driven and CO2 emissions, and to predict the potential emissions for a new trip length.

Write a MATLAB program to do the following:

1. Use readmatrix to load the FleetEmissionData.csv file (you can download a copy from the D3 link), which contains two columns:

· Column 1: Miles driven by each vehicle during the week

· Column 2: CO2 emissions (in kg) corresponding to the miles driven.

2. Create a scatter plot of CO2 emissions (Y-axis) vs miles driven (X-axis). Remember to include appropriate axis labels (with units) and a descriptive title.

3. Use polyfit to determine the coefficients of a linear relationship between miles driven and CO2 emissions. You can assume the relationship is linear, so fit a first-degree polynomial (line). Add this line to your scatter plot to represent the estimated relationship (remember to use “hold on” to do an overlay).

4. Use fprintf to display the equation of the best fit line.  Format the slope (m) with 2 decimal places and the intercept (k) with 0 decimal places.  Hint, to format a number with 0 decimal places, you can use %.0f. Remember to also explain the variables as part of the equation.

5. Calculate the estimated CO2 emissions for a trip of 500 miles by using the formula for the best fit line.   Use disp or fprintf to output the value.  The predicted emissions for a 500-mile trip should be about 257 kg.

Based on the scatter plot that you created in step 2, answer the following question in the space provided in the mlx template:

There are several vehicles that have driven approximately 400 miles, but the CO2 emissions have a relatively large variation (ranging from about 100kg to about 280kg, see Figure 1.  What are two factors that could have contributed to such a large variation in the amount of CO2 emissions?

 

Figure 1. Part of the graph highlighting variation in CO2 emissions for vehicles that that have been driven for about 400 miles

Deliverables

Please submit the following three files to Canvas:

· .mlx file for Problems 1 and 2 combined

· A template for your .mlx   file is provided in the D3 link on Canvas.

· Make sure the name and the date at the top of the .mlx file are updated with your information.

· Use the file naming convention D3_yourPID.mlx

· .csv file for Problem 1 above

· Use the file naming convention LastnameFirstname_Inventory.csv

· A single .pdf file of your .mlx file

o Make sure you run your .mlx with the sample run input values before making your PDF.  Use Live Editor>Export>Export to PDF menu option in MATLAB to make your PDF.   Graders need to be able to see the code and the sample output values/ figures in your PDF.  Use the file naming convention D3_yourPID_optional descriptor.pdf

If your computer is giving your problems with converting the MATLAB plot to your PDF, here are a few possible things to try to;

1. See if someone from SWAT (swat.eng.vt.edu) can help you with your graphics problem

2. Use the "print" option and choose PDF annotator if you have that installed (PDF annotator comes with your engineering bundle)

3. See if you can do a screen capture of the graph and insert that image into your mlx and then try exporting

4. Do a screen capture of your graph, then open your pdf in PDF annotator, add a new page to your pdf and paste the screen capture of your graph into it.

5. Copy and paste images of your mlx file into a document or PDF annotator and save as a PDF.

If you do #3, 4 or 5 successfully, please add a comment to the D3 link that lets the grader know that you had to do a workaround due to your graphics problem.

Rubric

Your work will be evaluated based on

· Program functionality

· Correctness of solutions

· Good programming practices - especially with respect to commenting and variable naming

· Readability and inclusion of requested elements

You can see the point breakdown in the table below         

<think>嗯,用户询问的是"计算机科学与编程中的图形学",这是一个跨学科的领域,需要从多个角度解释。首先需要明确用户可能关注的三个核心方向:计算机图形学基础、图形编程技术、以及相关数学基础。 用户提供的引用材料中有几个关键线索:引用[3]提到微分几何和代数几何在图像处理中的作用,引用[4]讨论图形化编程模型,引用[5]则涉及Java图形界面开发。这些应该成为回答的重要参考依据。 在构建回答框架时,考虑分四个层次展开:首先是基础理论部分,要强调图形学中的核心算法和数学原理,特别是引用[3]提到的几何学应用;接着是图形API部分,需要区分OpenGL/Vulkan等底层接口和Unity/Unreal等高级引擎;然后是应用领域,准备结合引用[5]的GUI案例说明;最后补充必要的数学基础,呼应引用[3]的内容。 注意到用户身份可能是计算机专业学生或开发者,回答需要兼顾理论深度和技术实践性。在图形渲染管线部分,考虑用OpenGL的渲染流程作为示例,既展示技术细节又避免过于抽象。应用场景列举时,特意加入游戏开发和VR等热门领域,增强实用性。 生成的问题设计成阶梯式:从基础概念到具体技术实现,再到前沿趋势。特别是第三个问题关于几何数学,直接对应引用[3]的内容,形成知识闭环。最后用计算机图形学的跨学科特性作为结语,呼应开篇的领域划分。 所有数学表达都严格遵循系统指令,比如视口变换公式使用$$...$$独立成段,Phong光照模型的变量用$...$行内标注。技术术语首次出现时都给出中英文对照,避免理解偏差。</think>好的,我们来探讨一下**计算机科学与编程中的图形学(Graphics in Computer Science and Programming)**。 计算机科学中的“图形学”(Graphics)是一个广阔且充满活力的领域,它专注于**使用计算机创建、处理、分析和显示视觉内容**。这远不止是简单的图片显示,而是涉及从基础数学、算法设计到硬件交互和用户体验设计的复杂过程。核心目标是将数据或概念转化为人类视觉系统能够理解和交互的形式。 ## 1. 核心领域:计算机图形学 (Computer Graphics) 这是图形学中最核心的分支,主要研究如何用计算机**合成和操作视觉内容**。它包含两大主要方向: * **光栅图形 (Raster Graphics):** * **概念:** 将图像表示为像素(Pixel)网格,每个像素存储颜色信息(如RGB值)。这是数字照片、屏幕显示和大多数位图图像的基础。 * **关键操作:** * **渲染 (Rendering):** 将场景描述(3D模型、光照、材质等)转换成最终的2D像素图像。这是核心挑战。 * **光栅化 (Rasterization):** 将几何图元(点、线、三角形)转换为像素网格的过程。这是实时图形(如游戏)的主要方法。 * **纹理映射 (Texture Mapping):** 将图像(纹理)包裹在3D模型表面以增加细节。 * **抗锯齿 (Anti-aliasing):** 减少由于像素离散性导致的边缘锯齿状效果。 * **图像处理 (Image Processing):** 对现有像素图像进行操作,如滤波、锐化、模糊、颜色调整等。 * **矢量图形 (Vector Graphics):** * **概念:** 使用数学公式(点、线、曲线、形状)来描述图像。图像由几何对象定义,而不是像素网格。 * **特点:** 无限缩放不失真(分辨率无关)、文件通常较小(尤其对于简单图形)、易于编辑。常用于Logo、插图、工程制图(CAD)、字体(TrueType, OpenType)和SVG(Scalable Vector Graphics)等。 * **操作:** 主要涉及几何变换(平移、旋转、缩放)和布尔运算(并、交、差)。 ## 2. 图形编程 (Graphics Programming) 这是实现计算机图形学技术的实践层面,涉及使用编程语言和特定的API(应用程序接口)来控制和操作图形硬件(GPU - Graphics Processing Unit)。 * **图形API (Graphics APIs):** 提供标准化的接口,让程序员能够访问GPU的强大功能,而不需要直接与复杂的硬件细节打交道。主要分为两类: * **低级API:** 提供更接近硬件的控制,灵活性高,但学习曲线陡峭。 * `OpenGL`:跨平台(桌面、移动、Web via WebGL)的经典API。 * `Vulkan`:OpenGL的现代继任者,更低开销,更高效,更复杂。 * `DirectX` (特别是 `Direct3D`):微软主导,主要在Windows/Xbox生态。 * `Metal`:苹果公司为其生态系统(macOS, iOS, iPadOS)开发的高性能API。 * **高级API/引擎:** 建立在低级API之上,提供更易用的抽象层和丰富的功能(场景管理、物理、动画、资源管理等)。 * `Unity`:非常流行的跨平台游戏引擎,也广泛用于VR/AR、建筑可视化等。 * `Unreal Engine`:以高保真渲染效果著称的尖端游戏引擎。 * `WebGPU`:新兴的Web标准,旨在为Web带来现代GPU功能(替代/增强WebGL)。 * **着色器编程 (Shader Programming):** 现代图形编程的核心。着色器是运行在GPU上的小程序,用于控制渲染管线的关键阶段: * **顶点着色器 (Vertex Shader):** 处理每个顶点的位置、法线、纹理坐标等。 * **片段/像素着色器 (Fragment/Pixel Shader):** 计算每个像素的最终颜色,处理光照、材质、纹理采样等。这是实现视觉效果(如Phong光照模型)的关键。 * **几何着色器 (Geometry Shader)、曲面细分着色器 (Tessellation Shaders):** 用于更高级的几何操作。 * **计算着色器 (Compute Shader):** 利用GPU进行通用并行计算,不仅限于图形(GPGPU - General Purpose GPU),在图形学中也用于物理模拟、粒子系统等。 * **图形管线 (Graphics Pipeline):** 描述数据从3D场景描述到最终2D屏幕像素的处理流程。理解管线是图形编程的基础。一个简化的OpenGL管线流程如下: ``` 顶点数据 -> [顶点着色器] -> 图元装配 -> 光栅化 -> [片段着色器] -> 测试与混合 -> 帧缓冲区 ``` ## 3. 应用领域 图形学的应用极其广泛,几乎渗透到所有与视觉相关的计算领域: 1. **游戏开发 (Game Development):** 实时渲染复杂3D场景、角色、特效的核心技术。 2. **计算机辅助设计 (CAD) / 计算机辅助制造 (CAM):** 用于工程设计、建筑规划、产品建模和可视化。 3. **数据可视化 (Data Visualization):** 将复杂数据(科学数据、商业数据、网络数据等)转化为直观的图表、图形、地图或交互式3D视图,帮助理解和发现模式。 4. **虚拟现实 (VR) 与 增强现实 (AR):** 创建沉浸式或混合现实体验的基础。 5. **电影与动画 (Film & Animation):** 特效(VFX)、3D动画、渲染逼真场景(离线渲染)。 6. **用户界面 (UI) 与 用户体验 (UX) 设计:** 设计操作系统、网站、应用程序的视觉元素和交互流程。现代UI框架(如引用[5]提到的Java Swing及其继承者JavaFX,以及Qt, WPF, Flutter, SwiftUI等)都依赖于底层图形系统进行绘制[^5]。 7. **图像处理与计算机视觉 (Image Processing & Computer Vision):** * **图像处理:** 修改或增强现有图像(如Photoshop功能)。 * **计算机视觉:** 让计算机“理解”图像和视频的内容(如目标检测、人脸识别、自动驾驶感知)。虽然目标不同(图形学是“生成”,视觉是“理解”),但两者在底层技术(如特征提取、图像变换)上有大量交叉。 8. **模拟 (Simulation):** 飞行模拟器、驾驶模拟器、科学现象可视化等。 9. **字体渲染 (Font Rendering):** 将矢量字体描述高效地转换为屏幕像素。 10. **信息图形 (Infographics):** 创建信息丰富的静态或交互式视觉表示。 11. **地理信息系统 (GIS):** 地图绘制和空间数据分析的可视化。 ## 4. 基础数学 图形学(尤其是3D图形和渲染)建立在深厚的数学基础之上: * **线性代数 (Linear Algebra):** 向量、矩阵运算(变换:平移、旋转、缩放)、坐标系变换(模型、视图、投影)、点积、叉积。这是**最核心**的数学工具。 * **微积分 (Calculus):** 理解连续变化(如动画曲线)、光照模型(积分)、曲面几何。 * **几何学 (Geometry):** 特别是**解析几何**(点、线、面、曲线、曲面的方程表示)和**投影几何**(3D到2D的映射)。微分几何在处理复杂曲面时很重要[^3]。 * **三角学 (Trigonometry):** 角度、旋转、正弦/余弦波(常用于动画和特效)。 * **概率与统计 (Probability & Statistics):** 在高级渲染技术(如光线追踪中的蒙特卡洛积分)、噪声生成、模拟中应用广泛。 ## 关键概念总结 * **从抽象到像素:** 图形学的核心挑战是将抽象的数学描述(模型、光照、材质)高效、准确地转化为屏幕上可见的像素。 * **性能至关重要:** 尤其是实时应用(游戏、VR),需要极高的计算效率,这推动了GPU硬件和图形API的快速发展。 * **跨学科性:** 融合了计算机科学、数学、物理学(光学)、艺术设计和人机交互。 * **硬件驱动:** GPU架构的演进(如可编程着色器的出现、光线追踪硬件加速)极大地推动了图形学的能力边界。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值