matlab怎么写代码

1. 数学实验 matlab的准确编写代码 % 首先可以构造网格数据,然后plot3绘图 。
%
% 代码:
clc; clear all; close all;
% 构造x数据
x = linspace(-10, 10);
% 构造y数据
y = linspace(-10, 10);
% 生成网格数据
[x, y] = meshgrid(x, y);
% 计算z
z = x.^3+8*x.^2+5*x-2*x.*y.^2+y+4;
% 绘图
figure;
plot3(x, y, z, 'r-');
box on;
2. matlab的程序应该怎么写 1、matlab是一个功能强大的软件,不仅仅在数据处理方面很优秀,在界面编程方面同样优秀,这里简单介绍下matlab界面编程的基础步骤 。
2、在打开的matlab程序中,点击new---graphic user interface,打开创建gui向导--我们选择blank gui,创建空白的gui界面---选择左侧我们需要的控件,如下图,我们选择一个button---将控件拖入到gui界面的合适的位置,双击打开设置属性的界面---设计好界面后,我们先不要编写函数内容,先运行界面---他会提醒我们激活界面将保存界面和代码,我们选择yes---输入文件名,点击保存---我们回到界面编辑界面,点击button右键打开右键菜单,点击view callbacks---callback,来跳转到该控件的回调函数---我们在该函数中输入代码---这时,我们运行程序,点击按钮,即可以在命令窗口中看到button执行的效果 。
3、先运行界面,使得matlab给我们创建界面的代码,然后在view callback 。
3. MATLAB 怎么写 下面是二分法的函数文件,你直接设置输入参数就可以了function [c,err,yc]=bisect(f,a,b,delta)%Input - f is the function % - a and b are the left and right endpoints% - delta is the tolerance%Output - c is the zero% - yc= f(c)% - err is the error estimate for c%If f is defined as an M-file function use the @ notation% call [c,err,yc]=bisect(@f,a,b,delta).%If f is defined as an anonymous function use the% call [c,err,yc]=bisect(f,a,b,delta).% NUMERICAL METHODS: Matlab Programs% (c) 2004 by John H. Mathews and Kurtis D. Fink% Complementary Software to accompany the textbook:% NUMERICAL METHODS: Using Matlab, Fourth Edition% ISBN: 0-13-065248-2% Prentice-Hall Pub. Inc.% One Lake Street% Upper Saddle River, NJ 07458ya=f(a);yb=f(b);if ya*yb > 0,return,endmax1=1+round((log(b-a)-log(delta))/log(2));for k=1:max1 c=(a+b)/2; yc=f(c); if yc==0 a=c; b=c; elseif yb*yc>0 b=c; yb=yc; else a=c; ya=yc; end if b-a < delta, break,endendc=(a+b)/2;err=abs(b-a);yc=f(c);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%建立该函数文件,拷至matlab的当前路径里 。
举个例子:>> format long>> [answer,error,value]=bisect(@(x)x-cos(x),0,1,1e-8)answer = 0.739085134118795error = 7.450580596923828e-009value = http://www.xuexi88.com/zhishi/1.512334035780327e-009answer即是方程 x-cos(x)=0 的根,error 是实际误差,value是计算结果回代到方程左边的值 。
4. MATLAB编程题,请问代码怎么写 Take a photo of yourself
//no operations
Read your photo with Matlab
//I=imread('aa.jpg');
Transform the photo from color image to gray image
//I_gray=rgb2gray(I);
Re-size the image (H*W=300*600)
//H=300;W=600;
//I_reshape=reshape(I_gray,H,W);
Transform the data format from 'uint8' to 'double'
//I_double=double(I_reshape);
Adjust the contrast of the image based on the equation
OUT = Average + (IN – Average) * ( 1 + percent)
//
Average=xxxx;
percent=xxxx;
for i=1:H
for j=1:W
I_out(i,j)= Average + (I_double(i,j) – Average) * ( 1 + percent);
end
end
Save the result image with 'jpg' format
//imwrite(uint8(I_out),'a_out.jpg');
5. 如何在matlab中写代码,求解,爸爸们 题主给出的积分方程,可以使用双循环语句和数值积分函数来求解T(x,t) 。
求解思路如下: 首先,根据x,t的范围值,将x,t值细分,即使用linspace函数,把x和t等分50(这个可以根据你的要求而改变) x=linspace(0,6,50);t=linspace(0,5400,50); 其二,使用for语句,循环二次,即 for i=1:length(x1) x=x1(i); for j=1:length(t1) t=t1(i);。